<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {

    public function index(){
        $this->assign('title','首页');
        $this->display();
    }
    public function shop_list(){
        $list = M('shop')->select();
        $this->list=$list;
        $this->assign('title','店铺列表');
        $this->display();
    }
    public function add_shop() {
        $this->assign('title','添加店铺');
    	$this->display();
    }   
    public function edit_shop() {
    	$id = I('id');
    	$shop_info = $this->select_shop($id);
    	$this->data = $shop_info;
        $this->assign('title','修改店铺');
    	$this->display();
    }
    public function del_shop() {
        $id = I('id');
        if (M('shop')->delete($id)>0){
            $this->success('删除成功',U('index'));
        } else {
            $this->error('删除失败');
        }
    }
    public function update_shop() {
    	$data =I('post.');
    	if (M('shop')->save($data)>0){
            $this->success('修改成功',U('index'));
        }else{
            $this->error('修改失败');
        }
    }
    public function select_shop($data) {
    	$shop_info = M('shop')->find($data);
    	return $shop_info;
    }
    public function insert() {
    	$data =I('post.');
        $data['address'] = $data['province'].$data['city'].$data['district'].$data['address'];
    	if (M('shop')->add($data)){
            $this->success('添加成功',U('index/index'));
        }else{
            $this->error('添加失败');
        }
    }
}